package controller.tables;

import java.util.ArrayList;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import model.Posterminal;
import model.PosterminalList;

@ManagedBean
@SessionScoped
public class Tables {
	private Integer posId;
	private String addressName;
	private PosterminalList pList = new PosterminalList("test");
	private int posCount = pList.getPosterminalsCount();
	
	public ArrayList<Posterminal> getPosterminals() {
		posCount = pList.getPosterminalsCount();
		return pList.getPosterminals();
	}
	
	public String addPosterminal() {
		Posterminal pos = new Posterminal(getPosId(), getAddressName()); 
		pList.addPosterminal(pos);
		posCount = pList.getPosterminalsCount();
		return (null);
	}
	
	public Integer getPosId() {
		return posId;
	}
	
	public void setPosId(Integer posId) {
		this.posId = posId;
	}
	
	public String getAddressName() {
		return addressName;
	}
	
	public void setAddressName(String addressName) {
		this.addressName = addressName;
	}
	
	public int getPosCount(){
		return posCount;
	}
	
	public String editAction(Posterminal posterminal) {
		posterminal.setEditable(true);
		return (null);
	}
	
	public String safeAction() {
		for (Posterminal posterminal : pList.getPosterminals()) {
			posterminal.setEditable(false);
		}
		return (null);
	}

}
